import type { AuthTree, PermissionItem, PermissionSaveResult, RolePageData, RoleSaveRequest, RoleSearchParams, TransferParams } from '@/types/RoleAuthorization.ts';
import http from '@/utils/RequestUtils';

const commonUrlPrefix = `${import.meta.env.VITE_API_BASE_FOUNDATION}`;
// 获取表格数据
export async function getRoleList(params: RoleSearchParams): Promise<CommonResponseData<RolePageData>> {
  return http.post<RolePageData>(`${commonUrlPrefix}/api/perm/role/list`, params);
}

// 获取授权页面穿梭树数据
export async function getRoleAuthorizationList(params: TransferParams): Promise<CommonResponseData<AuthTree>> {
  return http.post<AuthTree>(`${commonUrlPrefix}/api/perm/role/functions`, params);
}

// 获取授权页面继承权限数据
export async function getRoleAuthorizationInheritanceList(params: TransferParams): Promise<CommonResponseData<PermissionItem[]>> {
  return http.post<PermissionItem[]>(`${commonUrlPrefix}/api/perm/role/inherited-functions`, params);
}

// 获取授权页面全部权限数据
export async function getRoleAuthorizationAllList(params: TransferParams): Promise<CommonResponseData<PermissionItem[]>> {
  return http.post<PermissionItem[]>(`${commonUrlPrefix}/api/perm/role/all-functions`, params);
}

// 保存授权数据
export async function getRoleAuthorizationSave(params: RoleSaveRequest): Promise<CommonResponseData<PermissionSaveResult>> {
  return http.post<PermissionSaveResult>(`${commonUrlPrefix}/api/perm/role/save-functions`, params);
}

// 获取左侧树数据
export async function getRoleTreeList(params: any) {
  return http.post(`${commonUrlPrefix}/api/v1/extend-org/load`, params);
}
